import json

# 探索数据的结构
filename = "data/eq_data_1_day_m1.json"
with open(filename) as f:
    all_eq_data = json.load(f) # json.load(f)导入json文件f，以字典形式返回

# print(all_eq_data)

# readable_file = 'data/readable_eq_data.json'
# with open(readable_file, 'w') as f:
#     json.dump(all_eq_data, f, indent=4) # json.dump()将json数据对象(字典形式存储的)写入文件f中，indent指定缩进空格数，也可传递一个字符串作为缩进(如\t)
#     # dump：倾倒

all_eq_dicts = all_eq_data['features'] # 字典中键'features'对应的值是一个列表
# print(len(all_eq_dicts))

# 提取所有的震级数据
mags, titles, lons, lats = [], [], [], []
for eq_dict in all_eq_dicts:
    mag = eq_dict['properties']['mag']
    title = eq_dict['properties']['title']
    lon = eq_dict['geometry']['coordinates'][0] # 经度
    lat = eq_dict['geometry']['coordinates'][1] # 纬度
    mags.append(mag)
    titles.append(title)
    lons.append(lon)
    lats.append(lat)

# print(mags[:10])
# print(titles[:2])
# print(lons[:5])
# print(lats[:5])